define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'service/log/index' + location.search,
                    add_url: 'service/log/add',
                    edit_url: 'service/log/edit',
                    del_url: 'service/log/del',
                    multi_url: 'service/log/multi',
                    import_url: 'service/log/import',
                    table: 'service_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'customer.name', title: __('Customer.name'), operate: 'LIKE',
                            formatter: function (value, row, index) {
								if(!row.customer) return '-';
								value='<a href="javascript:void(0);" data-url="facrm/customer/index/detail/ids/'+ row.customer.id
									+'" data-area="[&quot;98%&quot;,&quot;98%&quot;]" class="btn-dialog" data-title="'+ row.customer.name+'">'+ row.customer.name +'('+row.customer.id+')'+'</a>';
								return value;
                            },
                        },
                        {field: 'project.name', title: __('Project.name'), operate: 'LIKE',
                            formatter: function (value, row, index) {
								if(!row.project) return '-';
								value='<a href="javascript:void(0);" data-url="workteam/project/detail/ids/'+ row.project.id
									+'" data-area="[&quot;98%&quot;,&quot;98%&quot;]" class="btn-dialog" data-title="'+ row.project.id+'">'+ row.project.name +'</a>';
								return value;
                            },
                        },
                        {field: 'task.name', title: __('Task.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'service_client_text', title: __('Service_client'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'service_time', title: __('Service_time'), sortable: true, operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'service_hours', title: __('Service_hours'), sortable: true, operate: false},
                        {field: 'content_text', title: __('Content_text'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'secret_text', title: __('Secret_text'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
				$("#c-project_id").data("params", function (obj) {
				    return {custom: {customer_id: $("#c-customer_id").val()}};
				});
				$("#c-task_id").data("params", function (obj) {
				    return {custom: {project_id: $("#c-project_id").val()}};
				});

                Form.api.bindevent($("form[role=form]"), function(data, ret){
                    //绑定时间
                    Fast.api.close(data);//在这里关闭当前弹窗
                });
            }
        }
    };
    return Controller;
});
